<script>
import dmbTable from "@/components/LTable/index.vue";
import {
  tableBase,
  cellStyle,
  headerCellStyle,
  tableFormStyle,
} from "./config";
import { carrier_DelAPI } from "@/api/data/carrier.js";

import { carrier_ListAPI } from "@/api/data/carrier.js";
import dayjs from "dayjs";
export default {
  name: "carrier",
  computed: {
    tableFormStyle() {
      return tableFormStyle;
    },
    cellStyle() {
      return cellStyle;
    },
    headerCellStyle() {
      return headerCellStyle;
    },
  },
  components: { dmbTable },
  data() {
    return {
      requestConfig: {
        url: "/base/manageCarrier/queryList",
        method: "get",
        montage: true,
      },
      saveRequest: {
        url: "/base/manageCarrier/save",
        method: "put",
        montage: false,
      },
      propsSearchForm: {},
      selectionArr: [], // 多选框内容
      inputfile: null,
      tableBase,
    };
  },
  methods: {
    // 删除
    del(id) {
      this.$confirm("确定要删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        carrier_DelAPI(id).then(() => {
          this.$refs.table.getListData();
          this.$message.success("删除成功");
        });
      });
    },
    // 导出
    async downLoad() {
      if (this.selectionArr.length > 0) {
        const ids = this.selectionArr.map((item) => {
          return item.id;
        });
        this.download(
          "/base/manageCarrier/export",
          {
            ids,
          },
          `承运商_${dayjs().format("YYYY-MM-DD HH:mm:ss")}.xlsx`
        );
      } else {
        this.$message.error("请选择条数据导出");
      }
    },
  },
};
</script>

<template>
  <div>
    <div class="mb-3">
      <template class="flex flex-row-reverse">
        <div class="my-3 flex flex-row-reverse">
          <div>
            <el-button type="success" @click="$refs.table.getListData()"
              >查询</el-button
            >
            <el-button type="success" @click="$refs.table.saveToUpdate()"
              >保存</el-button
            >
            <el-button type="primary" @click="downLoad">导出 </el-button>
          </div>
        </div>
      </template>
    </div>

    <div>
      <dmb-table
        ref="table"
        :props-search-form="propsSearchForm"
        :prop-list="tableBase"
        :operateWether="true"
        :is-operate="true"
        :show-index-column="true"
        select-column-type="CHECKBOX"
        :isSaveToUpadate="true"
        :req-request="requestConfig"
        :saveRequest="saveRequest"
        select-key="id"
        :cell-style="cellStyle"
        :header-cell-style="headerCellStyle"
        :initialize="false"
        :change-search-form="false"
        :show-footer="true"
        :form-item-style="tableFormStyle"
        @selectionChange="
          (row) => {
            selectionArr = row;
          }
        "
      >
        <template v-slot:operate="{ row }">
          <el-button type="danger" v-if="row.id" @click="del(row.id)"
            >删除</el-button
          >
        </template>
        <template v-slot:isPrint="{ row }">
          <el-checkbox v-model="row.isPrint" :true-label="1" :false-label="0">
          </el-checkbox>
        </template>
        <template v-slot:isEffective="{ row }">
          <el-checkbox
            v-model="row.isEffective"
            :true-label="1"
            :false-label="0"
          >
          </el-checkbox>
        </template>
      </dmb-table>
    </div>
  </div>
</template>

<style scoped lang="scss">
</style>
